/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * cadastroProp.java
 *
 * Created on 29/09/2009, 21:32:55
 */

package cparc;


import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

public class cadastroProp extends javax.swing.JInternalFrame {

    private boolean alterar = false;
    private boolean novo = false;
    static Home frameHome;

    public void setHome(Home home){

        frameHome = home;
        //System.out.println("Setando home");

    }

    public void bairro(String bCod, String bNom){
            
            tfCodBai.setText(bCod);
            tfNomBai.setText(bNom);
            tfCodBai.requestFocusInWindow();
            tfCodBai.selectAll();
    }

    public void rua(String rCod, String rNom){

            tfCodRua.setText(rCod);
            tfNomRua.setText(rNom);
            tfCodRua.requestFocusInWindow();
            tfCodRua.selectAll();
    }


    public void escPesqBairro(){

            tfCodBai.requestFocusInWindow();
            tfCodBai.selectAll();
    }

    public void escPesqRua(){

            tfCodBai.requestFocusInWindow();
            tfCodBai.selectAll();
    }

    public String getcodBai(){

        System.out.println(tfCodBai.getText());
        return tfCodBai.getText();
    }

    public void setTableModel(DefaultTableModel mod){

        tbProp.setModel(mod);

    }

    public void setLabProg(String text){

        label.setText(text);
    }

    /** Creates new form cadastroProp */
    public cadastroProp() throws SQLException {

        initComponents();

        tfCodProp.enable(false);
        tfNomProp.enable(false);
        tfCodBai.enable(false);
        tfNomBai.enable(false);
        tfCodRua.enable(false);
        tfNomRua.enable(false);
        tfNumProp.enable(false);
        tfTelProp.enable(false);
        tfRgProp.enable(false);

        Threads.cadPropTab thTable = new Threads.cadPropTab();
        thTable.setValues(this,(DefaultTableModel) tbProp.getModel(),"SELECT PCOD, PNOM FROM CPARC.CAD_PROP ORDER BY PNOM ASC");
        Thread t = new Thread(thTable);
        t.start();

        /*DefaultTableModel modelo = (DefaultTableModel) tbProp.getModel();
        Statement stm = null;
        String result = null;
        String consulta = "SELECT PCOD, PNOM FROM CPARC.CAD_PROP ORDER BY PNOM ASC";
        int i=0;

        try  {
        stm = (Statement) conexao.getConnection(true).createStatement();
        ResultSet rs = stm.executeQuery(consulta);

        while(rs.next()){
        modelo.addRow(new String[] {Integer.toString(rs.getInt("PCOD")), rs.getString("PNOM")});
        modelo.fireTableCellUpdated(i, 0);
        modelo.fireTableCellUpdated(i, 1);
        i++;
        }

        }
        catch(Exception e){
        String status = e.getMessage();
        System.out.println(status);
        }*/
   }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        label8 = new java.awt.Label();
        tfNomBai = new javax.swing.JTextField();
        label5 = new java.awt.Label();
        label4 = new java.awt.Label();
        tfCodRua = new javax.swing.JTextField();
        jcCad = new javax.swing.JCheckBox();
        tfCodBai = new javax.swing.JTextField();
        tfNomRua = new javax.swing.JTextField();
        label9 = new java.awt.Label();
        label3 = new java.awt.Label();
        btSalvar = new javax.swing.JButton();
        label7 = new java.awt.Label();
        tfNomProp = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbProp = new javax.swing.JTable();
        tfConsultaProp = new javax.swing.JTextField();
        btConsultar = new javax.swing.JButton();
        tfRgProp = new javax.swing.JTextField();
        label6 = new java.awt.Label();
        label1 = new java.awt.Label();
        btExcluir = new javax.swing.JButton();
        label2 = new java.awt.Label();
        tfTelProp = new javax.swing.JTextField();
        tfNumProp = new javax.swing.JTextField();
        tfCodProp = new javax.swing.JTextField();
        btEditar = new javax.swing.JButton();
        btNovo = new javax.swing.JButton();
        label = new javax.swing.JLabel();

        setClosable(true);
        setResizable(true);
        setTitle("Cadastro de Proprietários");
        setPreferredSize(new java.awt.Dimension(1050, 405));
        addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                formKeyPressed(evt);
            }
        });

        jPanel1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jPanel1KeyPressed(evt);
            }
        });

        label8.setText("Telefone");

        label5.setText("Rua");

        label4.setText(" Bairro");

        tfCodRua.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tfCodRuaKeyPressed(evt);
            }
        });

        jcCad.setText("Modo cadastro");

        tfCodBai.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tfCodBaiKeyPressed(evt);
            }
        });

        label9.setText("RG");

        label3.setText("Código do Bairro");

        btSalvar.setText("Salvar");
        btSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSalvarActionPerformed(evt);
            }
        });
        btSalvar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                btSalvarKeyPressed(evt);
            }
        });

        label7.setText("Número");

        tfNomProp.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tfNomPropKeyPressed(evt);
            }
        });

        tbProp.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Código", "Nome"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tbProp.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbPropMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tbProp);

        tfConsultaProp.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        tfConsultaProp.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tfConsultaPropKeyPressed(evt);
            }
        });

        btConsultar.setText("Consultar");
        btConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btConsultarActionPerformed(evt);
            }
        });

        tfRgProp.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tfRgPropKeyPressed(evt);
            }
        });

        label6.setText("Código da Rua");

        label1.setText("Código do Prorietário");

        btExcluir.setText("Excluir");
        btExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btExcluirActionPerformed(evt);
            }
        });

        label2.setText("Nome");

        tfTelProp.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tfTelPropKeyPressed(evt);
            }
        });

        tfNumProp.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tfNumPropKeyPressed(evt);
            }
        });

        tfCodProp.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tfCodPropKeyPressed(evt);
            }
        });

        btEditar.setText("Editar");
        btEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btEditarActionPerformed(evt);
            }
        });

        btNovo.setText("Novo");
        btNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btNovoActionPerformed(evt);
            }
        });

        label.setText("jLabel1");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(93, 93, 93))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(label3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(34, 34, 34)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(label6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(44, 44, 44))
                    .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(label7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(82, 82, 82))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(label9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(109, 109, 109))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(label8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(79, 79, 79)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tfCodProp, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(tfCodRua)
                            .addComponent(tfCodBai, javax.swing.GroupLayout.DEFAULT_SIZE, 55, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(label4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(label5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(tfNomRua)
                            .addComponent(tfNomBai, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jcCad)
                    .addComponent(tfNomProp, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(tfNumProp, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(tfRgProp, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(tfTelProp, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(btSalvar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                            .addComponent(btEditar)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(btExcluir)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(btNovo))))
                .addGap(16, 16, 16)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(label)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(tfConsultaProp, javax.swing.GroupLayout.DEFAULT_SIZE, 339, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(btConsultar))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 436, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tfConsultaProp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btConsultar))
                        .addGap(10, 10, 10)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 273, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addComponent(tfCodProp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(4, 4, 4)
                                .addComponent(tfNomProp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(label4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(tfNomBai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(label5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(tfNomRua, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addComponent(tfNumProp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(tfTelProp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(tfRgProp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                        .addComponent(tfCodBai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(tfCodRua, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(label3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(label6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(label7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(label8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(label9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(29, 29, 29)
                        .addComponent(jcCad)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btEditar)
                            .addComponent(btExcluir)
                            .addComponent(btNovo))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btSalvar)))
                .addGap(2, 2, 2)
                .addComponent(label)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(25, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(27, Short.MAX_VALUE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-919)/2, (screenSize.height-406)/2, 919, 406);
    }// </editor-fold>//GEN-END:initComponents

    private void btExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btExcluirActionPerformed

       if(tfCodProp.getText().isEmpty()){
           
           JOptionPane.showMessageDialog(rootPane, "Selecione um proprietário para excluir!", "Operação inválida", JOptionPane.WARNING_MESSAGE);
       
       }
       else{
            Object[] options = { "Confirmar", "Cancelar" };
            int n = JOptionPane.showOptionDialog(null, "Você está prestes a excluir o Proprietário: " + tfNomProp.getText() + "!\n Realizar a exclusão?", "Operação de exclusão!", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
            
            if (n == 0){
                
                Statement stm = null;
                String result = null;
                String consulta = "DELETE FROM CPARC.CAD_PROP WHERE PCOD = " + tfCodProp.getText();
                System.out.println(consulta);
        
                try  {
                    stm = (Statement) conexao.getConnection(true).createStatement();
                    int rs = stm.executeUpdate(consulta);
                    JOptionPane.showMessageDialog(rootPane, "Exclusão Efetuada Com Sucesso!", "Operação Realizada!", WIDTH);
                }
                catch(Exception e){
                    String status = e.getMessage();
                    System.out.println(status);
                    JOptionPane.showMessageDialog(rootPane, "Falha na Execução!", "Operação Não Realizada!", JOptionPane.ERROR_MESSAGE);
                    
                }
            
            }
        
        
       }

}//GEN-LAST:event_btExcluirActionPerformed

    private void btSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSalvarActionPerformed

        if(alterar){

            alterar = false;

            Object[] options = { "Confirmar", "Cancelar" };
            int n = JOptionPane.showOptionDialog(null, " Você está prestes a atualizar o proprietário: "+ tfNomProp.getText().toUpperCase() +"\nExecutar?", "Operação de atualização!", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);

            if (n == 0)
            {
                Statement stm = null;
                String result = null;
                String consulta = "UPDATE CPARC.CAD_PROP SET PNOM = '"+ tfNomProp.getText().toUpperCase() +"' , PBAI = "+ tfCodBai.getText() +", PEND = "+ tfCodRua.getText() +", PNUM = "+ tfNumProp.getText()+", PTEL = "+tfTelProp.getText() +" , PEND2 = '"+ tfRgProp.getText().toUpperCase() +"' WHERE PCOD = "+ tfCodProp.getText();
                //System.out.println(consulta);
                try  {
                    stm = (Statement) conexao.getConnection(true).createStatement();
                    int rs = stm.executeUpdate(consulta);
                    JOptionPane.showMessageDialog(rootPane, "Atualizacão Efetuada Com Sucesso!", "Operação Realizada!", WIDTH);
                }
                catch(Exception e){
                    String status = e.getMessage();
                    System.out.println(status);
                }

                tfCodProp.enable(false);
                tfNomProp.enable(false);
                tfCodBai.enable(false);
                tfNomBai.enable(false);
                tfCodRua.enable(false);
                tfNomRua.enable(false);
                tfNumProp.enable(false);
                tfTelProp.enable(false);
                tfRgProp.enable(false);
                tbProp.enable(true);
                this.repaint();
                tfConsultaProp.setText("");
                tfConsultaProp.requestFocusInWindow();
            }
            
            else{
            
                JOptionPane.showMessageDialog(rootPane, "Atualizacão Cancelada!", "Operação Cancelada!", WIDTH);
            
            }
                tfCodProp.enable(false);
                tfNomProp.enable(false);
                tfCodBai.enable(false);
                tfNomBai.enable(false);
                tfCodRua.enable(false);
                tfNomRua.enable(false);
                tfNumProp.enable(false);
                tfTelProp.enable(false);
                tfRgProp.enable(false);
                tbProp.enable(true);
                this.repaint();
                tfConsultaProp.setText("");
                tfConsultaProp.requestFocusInWindow();
        }

        else if (novo){

                Statement stm = null;
                String result = null;
                String consulta = "INSERT INTO CPARC.CAD_PROP (PCOD,PNOM,PBAI,PEND,PNUM,PCID,PEST,PTEL,PEND2) VALUES ("+ tfCodProp.getText() +",'"+ tfNomProp.getText().toUpperCase() +"',"+ tfCodBai.getText() +","+ tfCodRua.getText() +",'"+ tfNumProp.getText()+"','RIO CLARO','SP','"+tfTelProp.getText() +"','"+ tfRgProp.getText().toUpperCase() +"')";
                System.out.println(consulta);
                try  {
                    stm = (Statement) conexao.getConnection(true).createStatement();
                    int rs = stm.executeUpdate(consulta);
                    JOptionPane.showMessageDialog(rootPane, "Inserção Efetuada Com Sucesso!", "Operação Realizada!", WIDTH);
                }
                catch(Exception e){
                    String status = e.getMessage();
                    System.out.println(status);
                    JOptionPane.showMessageDialog(rootPane, "ERRO! OPERAÇÃO NÃO REALIZADA", "Operação Não Realizada!", JOptionPane.ERROR_MESSAGE);
                }

                if(jcCad.isSelected()){

                    btNovo.doClick();
                }

                else{
                    novo = false;
                    tfCodProp.enable(false);
                    tfNomProp.enable(false);
                    tfCodBai.enable(false);
                    tfNomBai.enable(false);
                    tfCodRua.enable(false);
                    tfNomRua.enable(false);
                    tfNumProp.enable(false);
                    tfTelProp.enable(false);
                    tfRgProp.enable(false);
                    tbProp.enable(true);
                    this.repaint();
                    tfConsultaProp.setText("");
                    tfConsultaProp.requestFocusInWindow();
                }
                
            }
        
}//GEN-LAST:event_btSalvarActionPerformed
      
    private void jbtAltActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtAltActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jbtAltActionPerformed

    private void formKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_formKeyPressed
        
    }//GEN-LAST:event_formKeyPressed


    private void formFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_formFocusGained
         
    }//GEN-LAST:event_formFocusGained

    private void tbPropMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbPropMouseClicked

        int line = tbProp.getSelectedRow();

        String cod = (String) tbProp.getValueAt(line, 0);
        String pnom = null;
        String pbai = null;
        String bnom = null;
        String pend = null;
        String rnom = null;
        String pnum = null;
        String ptel = null;
        String pend2 = null;


        Statement stm = null;
        String consulta = "SELECT * FROM CPARC.CAD_PROP WHERE PCOD = " + cod;
        
        try  {
            stm = (Statement) conexao.getConnection(true).createStatement();
            ResultSet rs = stm.executeQuery(consulta);
            rs.next();

            cod = rs.getString("PCOD");
            pnom = rs.getString("PNOM");
            pbai = rs.getString("PBAI");
            pend = rs.getString("PEND");
            pnum = rs.getString("PNUM");
            ptel = rs.getString("PTEL");
            pend2 = rs.getString("PEND2");
        }
        catch(Exception e){
            String status = e.getMessage();
            System.out.println(status + "aqui");
        }
       

        Statement stmBai = null;
        String consultaBai = "SELECT BNOM FROM CPARC.CAD_BAI WHERE BCOD = " + pbai;
        //CRIAANDO SQL ENCADEADA!!!
        try  {
            stmBai = (Statement) conexao.getConnection(true).createStatement();
            ResultSet rs = stm.executeQuery(consultaBai);
            rs.next();
            bnom = rs.getString("BNOM");

        }
        catch(Exception e){
            String status = e.getMessage();
            System.out.println(status + " bairro");
        }
       

        Statement stmRua = null;
        String consultaRua = "SELECT RNOM FROM CPARC.CAD_RUAS WHERE RCOD = " + pend;
        //CRIAANDO SQL ENCADEADA!!!
        try  {
            stmRua = (Statement) conexao.getConnection(true).createStatement();
            ResultSet rs = stm.executeQuery(consultaRua);
            rs.next();
            rnom = rs.getString("RNOM");
        }
        catch(Exception e){
            String status = e.getMessage();
            System.out.println(status + " rua");
        }
        

        tfCodProp.setText(cod);
        tfNomProp.setText(pnom);
        tfCodBai.setText(pbai);
        tfNomBai.setText(bnom);
        tfCodRua.setText(pend);
        tfNomRua.setText(rnom);
        tfNumProp.setText(pnum);
        tfTelProp.setText(ptel);
        tfRgProp.setText(pend2);
}//GEN-LAST:event_tbPropMouseClicked

    private void btConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btConsultarActionPerformed
        DefaultTableModel modelo = (DefaultTableModel) tbProp.getModel();

        String consText = tfConsultaProp.getText();
        tfConsultaProp.requestFocusInWindow();
        tfConsultaProp.selectAll();
        modelo.setRowCount(0);

        Threads.cadPropTab thTable = new Threads.cadPropTab();
        thTable.setValues(this,(DefaultTableModel) tbProp.getModel(),"SELECT PCOD, PNOM FROM cparc.cad_prop WHERE PNOM LIKE '" + consText + "%' ORDER BY PNOM ASC");
        Thread t = new Thread(thTable);
        t.start();

        /*Statement stm = null;
        String consulta = "SELECT PCOD, PNOM FROM cparc.cad_prop WHERE PNOM LIKE '" + consText + "%' ORDER BY PNOM ASC" ;
        int i=0;

        try  {
        stm = (Statement) conexao.getConnection(true).createStatement();
        ResultSet rs = stm.executeQuery(consulta);
        while (rs.next()){
        modelo.addRow(new String[] {Integer.toString(rs.getInt("PCOD")), rs.getString("PNOM")});
        modelo.fireTableCellUpdated(i, 0);
        modelo.fireTableCellUpdated(i, 1);
        i++;

        }

        }
        catch(Exception e){
        String status = e.getMessage();
        System.out.println(status);
        }*/


        
    }//GEN-LAST:event_btConsultarActionPerformed

    private void tfConsultaPropKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfConsultaPropKeyTyped
    }//GEN-LAST:event_tfConsultaPropKeyTyped

    private void tfConsultaPropKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfConsultaPropKeyPressed
 if (evt.getKeyCode() == 10)
        {
            tfConsultaProp.setText(tfConsultaProp.getText().toUpperCase());

            btConsultar.doClick();
        }
    }//GEN-LAST:event_tfConsultaPropKeyPressed

    private void btEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btEditarActionPerformed

        alterar = true;

        if (tfCodProp.getText().isEmpty())
        {
           JOptionPane.showMessageDialog(rootPane, "Selecione um proprietário para editar!", "Operação inválida", JOptionPane.WARNING_MESSAGE);
           alterar = false;
        }

        else{

            tfNomProp.enable(true);
            tfCodBai.enable(true);
            tfCodRua.enable(true);
            tfNumProp.enable(true);
            tfTelProp.enable(true);
            tfRgProp.enable(true);
            tbProp.enable(false);

            tfNomProp.requestFocusInWindow();
            tfNomProp.selectAll();
            this.repaint();
        }
    }//GEN-LAST:event_btEditarActionPerformed

    private void tfNomPropKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfNomPropKeyPressed

        if(evt.getKeyCode() == 10){

            tfCodBai.requestFocusInWindow();
            tfCodBai.selectAll();            
        }
    }//GEN-LAST:event_tfNomPropKeyPressed

    private void tfCodBaiKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfCodBaiKeyPressed
         if(evt.getKeyCode() == 10){

            Statement stm = null;
            String consulta = "SELECT BNOM FROM CPARC.CAD_BAI WHERE BCOD = " + tfCodBai.getText();

            try  {
                stm = (Statement) conexao.getConnection(true).createStatement();
                ResultSet rs = stm.executeQuery(consulta);
                rs.next();
                tfNomBai.setText(rs.getString("BNOM"));
            }


            catch(Exception e){
                String status = e.getMessage();
                System.out.println(status);
            }


                tfCodRua.requestFocusInWindow();
                tfCodRua.selectAll();
        }
         else if(evt.getKeyCode() == 114){

             pesqBairro bairro = new pesqBairro();
             bairro.setProp(this);
             frameHome.desk.add(bairro);
             bairro.setVisible(true);
         }
    }//GEN-LAST:event_tfCodBaiKeyPressed

    private void tfCodRuaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfCodRuaKeyPressed
         if(evt.getKeyCode() == 10){
             
             Statement stm = null;
            String consulta = "SELECT RNOM FROM CPARC.CAD_RUAS WHERE RCOD = " + tfCodRua.getText();

            try  {
                stm = (Statement) conexao.getConnection(true).createStatement();
                ResultSet rs = stm.executeQuery(consulta);
                rs.next();
                tfNomBai.setText(rs.getString("RNOM"));
            }


            catch(Exception e){
                String status = e.getMessage();
                System.out.println(status);
            }
            tfNumProp.requestFocusInWindow();
            tfNumProp.selectAll();
        }
          else if(evt.getKeyCode() == 114){

             pesqRuas rua = new pesqRuas();
             rua.setProp(this, tfCodBai.getText());
             //System.out.println(tfCodBai.getText());
             frameHome.desk.add(rua);
             rua.setVisible(true);
         }
    }//GEN-LAST:event_tfCodRuaKeyPressed

    private void tfNumPropKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfNumPropKeyPressed
         if(evt.getKeyCode() == 10){

            tfTelProp.requestFocusInWindow();
            tfTelProp.selectAll();
        }
    }//GEN-LAST:event_tfNumPropKeyPressed

    private void tfTelPropKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfTelPropKeyPressed
         if(evt.getKeyCode() == 10){

            tfRgProp.requestFocusInWindow();
            tfRgProp.selectAll();
        }
    }//GEN-LAST:event_tfTelPropKeyPressed

    private void tfRgPropKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfRgPropKeyPressed
         if(evt.getKeyCode() == 10){

            btSalvar.requestFocusInWindow();
        }
    }//GEN-LAST:event_tfRgPropKeyPressed

    private void jPanel1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jPanel1KeyPressed
        
    }//GEN-LAST:event_jPanel1KeyPressed

    private void btSalvarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_btSalvarKeyPressed

        if (evt.getKeyCode() == 10)

            btSalvar.doClick();
    }//GEN-LAST:event_btSalvarKeyPressed

    private void btNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btNovoActionPerformed

        novo = true;
        tfCodProp.enable(true);
        tfNomProp.enable(true);
        tfNomProp.setText("");
        tfCodBai.enable(true);
        tfCodBai.setText("");
        tfCodRua.enable(true);
        tfCodRua.setText("");
        tfNumProp.enable(true);
        tfNumProp.setText("");
        tfTelProp.enable(true);
        tfTelProp.setText("");
        tfRgProp.enable(true);
        tfRgProp.setText("");
        tfNomBai.setText("");
        tfNomRua.setText("");
        tbProp.enable(true);
        this.repaint();

        Statement stm = null;
            String consulta = "SELECT MAX(PCOD) AS ULT FROM CPARC.CAD_PROP";

            try  {
                stm = (Statement) conexao.getConnection(true).createStatement();
                ResultSet rs = stm.executeQuery(consulta);
                rs.next();
                tfCodProp.setText(String.valueOf(rs.getInt("ULT") + 1));
            }
            catch(Exception e){
                String status = e.getMessage();
                System.out.println(status);
            }

            tfCodProp.requestFocusInWindow();
            tfCodProp.selectAll();
    }//GEN-LAST:event_btNovoActionPerformed

    private void tfCodPropKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfCodPropKeyPressed

        if(evt.getKeyCode() == 10){

            //Talvez um dia verifique se ja existe o numero no bd
            tfNomProp.requestFocusInWindow();
        }
    }//GEN-LAST:event_tfCodPropKeyPressed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btConsultar;
    private javax.swing.JButton btEditar;
    private javax.swing.JButton btExcluir;
    private javax.swing.JButton btNovo;
    private javax.swing.JButton btSalvar;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JCheckBox jcCad;
    private javax.swing.JLabel label;
    private java.awt.Label label1;
    private java.awt.Label label2;
    private java.awt.Label label3;
    private java.awt.Label label4;
    private java.awt.Label label5;
    private java.awt.Label label6;
    private java.awt.Label label7;
    private java.awt.Label label8;
    private java.awt.Label label9;
    private javax.swing.JTable tbProp;
    public javax.swing.JTextField tfCodBai;
    private javax.swing.JTextField tfCodProp;
    private javax.swing.JTextField tfCodRua;
    private javax.swing.JTextField tfConsultaProp;
    private javax.swing.JTextField tfNomBai;
    private javax.swing.JTextField tfNomProp;
    private javax.swing.JTextField tfNomRua;
    private javax.swing.JTextField tfNumProp;
    private javax.swing.JTextField tfRgProp;
    private javax.swing.JTextField tfTelProp;
    // End of variables declaration//GEN-END:variables

}
